<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="num++">点击修改num</button>
        <h3>{{num}}</h3>
        <br>
        <hr>
        <div>
            <button @click="putName">修改名字</button>
            <button @click="addHobby">添加hobby属性</button>
            <button @click="deleteAge">删除age属性</button>
            <h3>{{goodData.name}}</h3>
            <h3>{{goodData.age}}</h3>
            <h3>{{goodData.sex}}</h3>
            <h3>{{goodData.hobby}}</h3>
        </div>
        <hr><br>
        <div>
            <button @click="put">修改</button>
            <button @click="add">添加</button>
            <button @click="deleteArr">删除</button>
            <h3 v-for="item,index in newList" :key="index">{{item}}</h3>
        </div>
    </div>
    <script>
        const vm = new Vue({
            data() {
                return {
                    num: 0, //简单数据可以直接修改触发响应式数据
                    goodData: {
                        name: "张三",
                        age: "18",
                        sex: "男"
                    },
                    newList: ["音乐...", "新闻...", "娱乐...", "电影"],
                }
            },
            methods: {
                putName() { //对象可以直接给已有的属性重新赋值
                    this.goodData.name = "赵六"
                },
                addHobby() { // 对象设置没有的属性使用Vue.set
                    Vue.set(this.goodData, "hobby", "敲代码")
                },
                deleteAge() {// 对象删除属性使用Vue.delete
                    Vue.delete(this.goodData, "age")
                },
                put(){
                    this.newList.splice(0,1,"旅行")
                },
                add(){
                    this.newList.push("打豆豆")
                },
                deleteArr(){
                    //遍历方法
                    this.newList=this.newList.filter(item => item !== "新闻...")
                }
            },
            computed: {

            },
            watch: {

            }
        }).$mount("#app")
    </script>
</body>

</html>